home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / ZIPPED / LISTINGS / V_12_05.ZIP / ALLISON.ZIP / SCOPE1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-04  |  637 b   |  34 lines

  1.  
  2. LISTING 1 -
  3. // scope1.cpp:  Shows that declarations are statements
  4. #include <iostream.h>
  5.  
  6. main()
  7. {
  8.     int a[] = {0,1,2,3,4};
  9.  
  10.     // Print address and size
  11.     cout << "a == " << (void *) a << endl;
  12.     cout << "sizeof(a) == " << sizeof(a) << endl;
  13.  
  14.     // Print forwards
  15.     size_t n = sizeof a / sizeof a[0];  // line 8
  16.     for (int i = 0; i < n; ++i)         // line 9
  17.         cout << a[i] << ' ';
  18.     cout << endl;
  19.  
  20.     // Then backwards
  21.     for (i = n-1; i >= 0; --i)
  22.         cout << a[i] << ' ';
  23.     cout << endl;
  24.     return 0;
  25. }
  26.  
  27. /* Output:
  28. a == 0xffec
  29. sizeof(a) == 10
  30. 0 1 2 3 4 
  31. 4 3 2 1 0 
  32. */
  33.  
  34.